const event = '/dev/input/event1',
cp = require('child_process');

function sendevent(type, code, value) {
	cp.exec(`D:\\mfp\\sdk\\platform-tools\\adb shell sendevent ${event} ${type} ${code} ${value}`, (err, stdout, stderr) => {
		if (err)
			throw err;
		//console.log(stdout)
		//console.log(stderr)
	})
}

//Press a point
function press(x, y) {
	sendevent(3, 0x35, x)
	sendevent(3, 0x36, y)
	sendevent(3, 0x30, 0x44)
	sendevent(3, 0x32, 0x04)
	sendevent(3, 0x39, 0x00)
	sendevent(0, 0x02, 0x00)
	sendevent(0, 0x00, 0x00)
}

//Release on a point
function release(x, y) {
	sendevent(3, 0x35, x)
	sendevent(3, 0x36, y)
	sendevent(3, 0x30, 0x00)
	sendevent(3, 0x32, 0x04)
	sendevent(3, 0x39, 0x00)
	sendevent(0, 0x02, 0x00)
	sendevent(0, 0x00, 0x00)
}

//Click on a point
function click(x, y) {
	press(x, y)
	release(x, y)
}

//Long click on a point
function longclick(x, y) {
	press(x, y)
	press(x, y)
	//sleep 1
}

//Fling from a point to another
function fling(x, y, x1, y1) {
	move(x, y, x1, y1)
	release(x1, y1)
}

//Drag and drop
function dad(x, y, x1, y1) {
	longclick(x, y)
	move(x, y, x1, y1)
	release(x1, y1)
}

//Move from a point to another
function move(x, y, x1, y1) {
	var _x,
	_y
	for (i in[1, 2, 3, 4]) {
		_x = $(((x1 - x) * i / 3 + x));
		_y = $(((y1 - y) * i / 3 + y));
		press(x, y)
	}
}

click(253, 802)
